#include <iostream>
#include <memory>
#include <string>
#include "tcp_server.hpp"
#include "daemon.hpp"

using namespace my_tpcs;

static void usage(const char* port)
{
    std::cout<<"USAGE:\n\t"<<port<<" serverip\n"<<std::endl;
}

std::string DataFunc(const std::string& s)
{
    return s;
}

int main(int argc,char* argv[])
{
    uint16_t port = 8088;
    if(argc == 2)
    {
        port = htons(atoi(argv[1]));
    }
    else if(argc > 2)
    {
        usage(argv[0]);
        exit(USAGE_ERR);
    }

    daemon(); //守护进程化

    std::unique_ptr<Server> ser(new Server(DataFunc,port));
    ser->InitServer();
    ser->Start();

    return 0;
}